# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=sfml

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
_ver_base=2.1.0
pkgver=2.1.0.1570.749cbb2
pkgrel=1
pkgdesc="A simple, fast, cross-platform, and object-oriented multimedia API (mingw-w64)"
arch=('any')
url="http://www.sfml-dev.org/"
license=("zlib")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-libsndfile"
        "${MINGW_PACKAGE_PREFIX}-libjpeg"
        "${MINGW_PACKAGE_PREFIX}-openal" 
        "${MINGW_PACKAGE_PREFIX}-glew"
        "${MINGW_PACKAGE_PREFIX}-freetype"
        )
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "git" "${MINGW_PACKAGE_PREFIX}-gcc")
source=("${_realname}"::"git+https://github.com/LaurentGomila/SFML.git"
        mingw-w64-msys2.patch)
md5sums=('SKIP'
         'c247c5b6590ac65a88a87a3fa544b6aa')

pkgver() {
  cd "$srcdir/$_realname"
  printf "%s.%s.%s" "$_ver_base" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${srcdir}/$_realname
  patch -p1 -i ${srcdir}/mingw-w64-msys2.patch
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

  [[ -d build-${MINGW_CHOST} ]] && rm -r build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd build-${MINGW_CHOST}
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${pkgdir}${MINGW_PREFIX} \
    -DSFML_BUILD_EXAMPLES=1 \
    -DSFML_BUILD_DOC=1 \
    -DSFML_INSTALL_PKGCONFIG_FILES=ON \
    ../$_realname

  make
  make doc
}

package() {
  cd build-${MINGW_CHOST}

  make install

  install -Dm644 "${pkgdir}${MINGW_PREFIX}/share/cmake/Modules/FindSFML.cmake" "${pkgdir}${MINGW_PREFIX}/share/cmake-2.8/Modules/FindSFML.cmake"
  install -Dm644 ${srcdir}/${_realname}/license.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
